package com.my.hzb.user.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.framelib.utils.Page;
import com.my.hzb.entiy.Address;
import com.my.hzb.entiy.AddressExample;
import com.my.hzb.mapper.AddressMapper;

public class AddressServiceImpl implements AddressService {

	@Autowired
	private AddressMapper addressMapper;
	
	@Override
	public void add(Address ads) {
		ads.setCreateTime(new Date());
		ads.setUpdateTime(new Date());
		addressMapper.insert(ads);
	}

	@Override
	public void update(Address ads) {

	}

	@Override
	public void delete(Address ads) {

	}

	@Override
	public Address getOne(Integer id) {
		return addressMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<Address> find(Address ads,Page page) {
		AddressExample example = new AddressExample();
		if(null!=page){
			example.setPage(page);
		}
		return addressMapper.selectByExample(example);
	}

	@Override
	public Address getDefByUser(String userName) {
		AddressExample example = new AddressExample();
		example.createCriteria().andUserNameEqualTo(userName).andStatusEqualTo(0);
		List<Address> adsList = addressMapper.selectByExample(example);
		if(null!=adsList&&adsList.size()>0){
			return adsList.get(0);
		}
		return null;
	}

}
